//
//  File.swift
//  DemoTest
//
//  Created by admin on 2022/4/24.
//

import Foundation

import SwiftUI

var screen = UIScreen.main.bounds
struct SendCake: View {
    @State var move = false
    @State var dialogue: Bool = false
    @State var running: Bool = false
    @State var showFinalVieW: Bool = false
    var body: some View {
        
        ZStack(alignment: .bottom) {
            
            HStack{
                VStack {
                    Spacer()
                    
                    if !dialogue {
                        Image("run1")
                            .resizable()
                            .aspectRatio(1/1, contentMode: .fit)
                            .frame(height: 200)
                            .offset(y: -screen.height / 5 - 12)
                    }
                    else {
                        Image("run1")
                            .resizable()
                            .aspectRatio(1/1, contentMode: .fit)
                            .frame(height: 200)
                            .offset(y: -screen.height / 5 - 12)
                            .onAppear(){
                                withAnimation(.easeInOut(duration: 4)) {
                                    running = true
                                }
                            }
                            .offset(x: running ? screen.width/2.7 : 0)
                        
                    }
                    
                    
                    
                }
                Spacer()
                    .frame(width: screen.width/2.7)
                
                VStack{
                    Spacer()
                    Image("standwoman")
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        .frame(width: 200, height: 200)
                        .offset(y: -screen.height / 5)
                    
                    
                }
                
                
            }
            
            VStack {
                Spacer()
                
                Image(dialogue ?  "textgiveg" : "textgiveboy")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .onTapGesture {
                        dialogue = true
                    }
                //                    .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
            }
            VStack {
                Spacer()
                HStack {
                    Spacer()
                    Button  {
                        showFinalVieW = true
                    } label: {
                        Image("nextButton")
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(width: 50, height: 50)
                            .padding()
                    }
                    .fullScreenCover(isPresented: self.$showFinalVieW, content: {FinalView()})
                }
            }
            
        }
        .background(
            HStack{
                Image("page4bk")
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
            }
        )
        .ignoresSafeArea()
    }
    
    
    
}

struct SendCake_Previews: PreviewProvider {
    static var previews: some View {
        SendCake()
            .previewInterfaceOrientation(.landscapeLeft)
    }
}
//struct BoyRun: View {
//
//    let images = ["run1", "run2", "run3"]
//
//    @State private var idx = 0
//
//    private let timer = Timer.publish(every: 0.5, on: .main, in: .common).autoconnect()
//
//    var transition: AnyTransition = .identity
//
//    var body: some View {
//        ZStack {
//            ForEach(images.indices, id: \.self) { index in
//                if self.idx == index {
//                    Image(self.images[index])
//                        .resizable()
//                        .aspectRatio(1/1, contentMode: .fit)
//                        .frame(height: 200)
//                        .offset(y: -screen.height / 5 - 12)
//                }
//            }
//
//
//        }.onReceive(timer) { _ in
//            //            withAnimation {
//            self.idx = self.idx < (self.images.count - 1) ? self.idx + 1 : 0
//            //            }
//        }
//    }
//}
